home *** CD-ROM | disk | FTP | other *** search
/ Mastering Computers 3 / Mastering Computers Vol 3.iso / Win95 / Fun&Utils / STRTMENU.EXE / ADDGROUP.CPP next >
Encoding:
C/C++ Source or Header  |  1995-07-21  |  4.1 KB  |  145 lines

  1. /**************************************************************************
  2.  
  3.    THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
  4.    ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
  5.    THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
  6.    PARTICULAR PURPOSE.
  7.  
  8.    Copyright (C) 1993-1995  Microsoft Corporation.  All Rights Reserved.
  9.  
  10.    File:          AddGroup.cpp
  11.    
  12.    Description:   Provides the functionality for adding a group to the 
  13.                   programs folder under the start menu.
  14.  
  15. **************************************************************************/
  16.  
  17. #define STRICT
  18.  
  19. /**************************************************************************
  20.    Include Files
  21. **************************************************************************/
  22.  
  23. #include <windows.h>
  24. #include <windowsx.h>
  25. #include <shlobj.h>
  26. #include "globals.h"
  27. #include "resource.h"
  28.  
  29. /**************************************************************************
  30.    Local Function Prototypes
  31. **************************************************************************/
  32.  
  33. BOOL CreateFolder(LPSTR);
  34. BOOL GetFolderName(HWND, LPSTR);
  35. BOOL CALLBACK GetFolderNameDlgProc(HWND, UINT, WPARAM, LPARAM);
  36.  
  37. /**************************************************************************
  38.    Global Variables
  39. **************************************************************************/
  40.  
  41. BOOL AddGroup(HWND hWnd)
  42. {
  43. LPITEMIDLIST   pidlStartMenu,
  44.                pidlDestination;
  45. char           szTemp[MAX_PATH],
  46.                szPath[MAX_PATH];
  47.  
  48. //get the pidl for the start menu - thgis will be used to intialize the folder browser
  49. SHGetSpecialFolderLocation(NULL, CSIDL_PROGRAMS, &pidlStartMenu);
  50.  
  51. //get the parent of the new folder
  52. if(!GetFolder(hWnd, &pidlDestination, pidlStartMenu, szTemp, "Select Location for Folder"))
  53.    return FALSE;
  54.  
  55. //get the path for the folder
  56. SHGetPathFromIDList(pidlDestination, szPath);
  57.  
  58. //get the name of the new folder
  59. GetFolderName(hWnd, szPath);
  60.  
  61. //create the folder
  62. CreateFolder(szPath);
  63.  
  64. return TRUE;
  65. }
  66.  
  67. /**************************************************************************
  68.  
  69.    CreateFolder()
  70.  
  71. **************************************************************************/
  72.  
  73. BOOL CreateFolder(LPSTR lpszFolder) 
  74. //create the folder
  75. CreateDirectory(lpszFolder, NULL);
  76.  
  77. //notify the shell that you made a change
  78. SHChangeNotify(SHCNE_MKDIR, SHCNF_PATH, lpszFolder, 0);
  79.  
  80. return TRUE;
  81. }
  82.  
  83. /**************************************************************************
  84.  
  85.    GetFolderName()
  86.  
  87. **************************************************************************/
  88.  
  89. BOOL GetFolderName(HWND hWnd, LPSTR lpszPath)
  90. {
  91. return DialogBoxParam(  g_hInstance, 
  92.                         MAKEINTRESOURCE(IDD_GET_NAME), 
  93.                         hWnd,
  94.                         GetFolderNameDlgProc,
  95.                         (LPARAM)lpszPath);
  96. }
  97.  
  98. /**************************************************************************
  99.  
  100.    GetFolderNameDlgProc()
  101.  
  102. **************************************************************************/
  103.  
  104. BOOL CALLBACK GetFolderNameDlgProc( HWND hWnd, 
  105.                                     UINT uMsg, 
  106.                                     WPARAM wParam, 
  107.                                     LPARAM lParam)
  108. {
  109. static LPSTR   lpszFolder;
  110.  
  111. switch(uMsg)
  112.    {
  113.    case WM_INITDIALOG:
  114.       lpszFolder = (LPSTR)lParam;
  115.       
  116.       SetWindowText(hWnd, "Enter Folder Name");
  117.       SetDlgItemText(hWnd, IDC_STATIC_TEXT, "Enter a name for the folder");
  118.       return TRUE;
  119.  
  120.    case WM_COMMAND:
  121.       switch (GET_WM_COMMAND_ID(wParam, lParam))
  122.          {
  123.          case IDOK:
  124.             {
  125.             char  szTemp[MAX_PATH];
  126.             
  127.             GetDlgItemText(hWnd, IDC_TEXT, szTemp, sizeof(szTemp));
  128.             lstrcat(lpszFolder, "\\");
  129.             lstrcat(lpszFolder, szTemp);
  130.             EndDialog(hWnd, TRUE);
  131.             }      
  132.             break;
  133.             
  134.          case IDCANCEL:
  135.             EndDialog(hWnd, FALSE);
  136.             break;
  137.          }
  138.       return TRUE;
  139.    }
  140.    
  141. return FALSE;
  142. }
  143.  
  144.